package com.example.helloword.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @create 2022-03-2022/3/10-17:03
 */
//拦截器
public class LoginHandleIntercepter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object now_usename=request.getSession().getAttribute("now_username");

        if (now_usename==null){
            request.setAttribute("msg","您还没有登录，请先登录");
            request.getRequestDispatcher("/hello").forward(request,response);
            return false;
        }else {
            return true;
        }
    }


}
